<?php
Class Admin extends CActiveRecord{
    public static function model($class= __CLASS__){
        return parent::model($class);
    }
    Public function tableName(){
        return 'admin';
    }
    public function checkUserExit($username){
        $sql = "select * from Admin where username = '".$username."'";
        $query = Yii::app()->db->createCommand($sql);
        if(count($query->queryAll())>0){
            return false;
        }else{
            return true;
        }
    }
    public function checkEmailExit($email){
        $sql = "select * from Admin where email = '".$email."'";
        $query = Yii::app()->db->createCommand($sql);
        if(count($query->queryAll())>0){
            return false;
        }else{
            return true;
        }
    }
    public function checkloginexit($username,$password){
        $sql = "select * from Admin where `username` = '".$username."' and `password`= '".$password."'";
        $query = Yii::app()->db->createCommand($sql);
        $check = count($query->queryAll());
        if ($check>0){
            return true;
        }else{
            return false;
        }
    }

    public static function GetAdmin($admin_id){
        $nameadmin =Admin::model()->findByPk($admin_id);
        if($nameadmin){
            return $nameadmin['username'];
        } else {
            return 'root';
        }

    }

}